package com.banmao.algorithm.No101To200.No142;

/**
 *  有问题，待处理
 */
public class Solution1 {

    public ListNode detectCycle(ListNode head) {
        if(head == null || head.next == null) {
            return null;
        }
        // 设置快慢指针
        // 快指针先走两步
        ListNode fast = head.next.next;
        ListNode slow = head;
        if(fast == null || fast.next == null || fast.next.next == null) {
            return null;
        }

        while(fast.next != null && fast.next.next != null) {
            if(slow == fast) {
                return slow;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return null;
    }


}

class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
        next = null;
    }
}


